package com.example.library_demo.controller;

import com.example.library_demo.entity.User;
import com.example.library_demo.service.IUserService;
import com.example.library_demo.util.HttpServletUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class BaseController {

    @Autowired
    private IUserService userService;

    public User getCurrentUser(){
        HttpServletRequest request = HttpServletUtil.getRequest();
        String token = request.getHeader("token");
        return userService.getUserByToken(token);
    }

}
